<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>

    <script>

        // 1+2+3+4+5

        // 1-5的和   1-4的和+5

        // 1-4的和   1-3的和+4

        // 1-3的和   1-2的和+3

        // 1-2的和   1的和+2

        // 1


        function sum(n) {
            if(n === 1) return 1 ;
            return sum(n-1) + n ;
        }

        document.write(sum(5));


        // sum(5) =   sum(4)+5
        // sum(3)+4
        // sum(2)+3    
        // sum(1)+2
        //  1




    </script>
    
</body>
</html>